#include "Database.h"

int main() {
	// init tabel
	TabelMhs TMhs = CreateEmptyTabelMhs();
	TabelMK TMK = CreateEmptyTabelMK();
	TabelPMK TPMK = CreateEmptyTabelPMK();
	
	// init graf
	nodeAddress A = AllocateNode(CharToString("A"), 0.01, 0.01, 0.01, 0.01, true, true);
	ChangeNodeTableAvailability(A, true,true, true);
	nodeAddress B = AllocateNode(CharToString("B"), 0.01, 0.01, 0.01, 0.01, true, true);
	ChangeNodeTableAvailability(B, true,true, true);
	nodeAddress C = AllocateNode(CharToString("C"), 0.01, 0.01, 0.01, 0.01, true, true);
	ChangeNodeTableAvailability(C, true,true, true);
	
	nodeList NL = CreateEmptyNodeList();
	AddNode(&NL, A);
	AddNode(&NL, B);
	AddNode(&NL, C);
	
	edgeList EL = CreateEmptyEdgeList();
	AddEdge(&EL, AllocateEdge(A,B,22.5,22.5));
	AddEdge(&EL, AllocateEdge(B,C,22.5,22.5));
	AddEdge(&EL, AllocateEdge(A,C,0.005,0.005));
	
	// inserting
	float time;
	char path[100];
	AddressMhs Ecky = AllocateRecordMhs(CharToString("13508004"), CharToString("Ecky"), MakeTanggal(12,04,1990), CharToString("Jakarta"));
	AddressMhs Nazi = AllocateRecordMhs(CharToString("13508001"), CharToString("Nazila"), MakeTanggal(12,04,1990), CharToString("Jakarta"));
	
	AddressMK IF2030 = AllocateRecordMK(CharToString("IF2030"), CharToString("Algoritma dan Struktur Data"), 4, CharToString("Pemrogaman"));
	AddressMK IF2031 = AllocateRecordMK(CharToString("IF2031"), CharToString("Algoritma dan Struktur Data"), 3, CharToString("Pemrogaman"));
	
	AddressPMK PMK0 = AllocateRecordPMK(Ecky, IF2030, 1, CreateThnAkademik(2008,2009), 'A');
	AddressPMK PMK1 = AllocateRecordPMK(Ecky, IF2031, 2, CreateThnAkademik(2008,2009), 'C');
	
	printf("Size Ecky : %d\n", GetRecordMhsSize(Ecky));
	printf("Size Nazi : %d\n", GetRecordMhsSize(Nazi));
	
	InsertRecordMhs(Ecky, &TMhs, B, A, EL, &time, path);
	printf("Insert record => %s : %f secs\n", path, time);
	InsertRecordMhs(Nazi, &TMhs, B, A, EL, &time, path);
	printf("Insert record => %s : %f secs\n", path, time);
	puts("Tabel Setelah penambahan record : ");
	PrintTabelMhs(TMhs);
	
	InsertRecordMK(IF2030, &TMK, B, A, EL, &time, path);
	printf("Insert Record MK ==> %s : %f secs\n", path, time);
	InsertRecordMK(IF2031, &TMK, B, A, EL, &time, path);
	printf("Insert Record MK ==> %s : %f secs\n", path, time);
	puts("Tabel Setelah penambahan record");
	PrintTabelMK(TMK);
	
	InsertRecordPMK(PMK0, &TPMK, B, A, EL, &time, path);
	printf("Insert Record PMK0 ==> %s : %f secs\n", path, time);
	InsertRecordPMK(PMK1, &TPMK, B, A, EL, &time, path);
	printf("Insert Record PMK1 ==> %s : %f secs\n", path, time);
	puts("TabelMhs setelah penambahan PMK");
	PrintTabelMhs(TMhs);
	
	puts("Ecky dirubah NIM nya");
	int count;
	UpdateRecordMhs(Ecky, CharToString("NIM_BARU"), NAMA(Ecky), TGLLAHIR(Ecky), KOTAASAL(Ecky), &count, &time);
	printf("Record ecky tereplikasi %d kali, diupdate dalam waktu %f\n",count,time);
	PrintTabelMhs(TMhs); puts("");
	PrintTabelPMK(TPMK); puts("");
	
	puts("IF2030 dihapus"); 
	DeleteRecordMK(IF2030, &TMK, &TPMK, &time, &count);
	printf("IF2030 tereplikasi %d kali, waktu penghapusan %f\n", count, time);
	PrintTabelMK(TMK); puts("");
	PrintTabelPMK(TPMK);

	return 0;
}